// service/exercise/exercise.js
import http from "../../utils/http"
import util from "../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    finish: false,
    loading: false,
    page: 1,
  },

  reload(){
    this.setData({
      list: [],
      page: 1,
      finish: false
    })
    this.getList()
  },
  more(){
    this.setData({
      page: ++this.data.page
    })
    this.getList()
  },
  getList(){
    if(this.data.finish){
      return 
    }
    if(this.data.loading){
      return 
    }
    this.setData({
      loading: true
    })
    let data = {
      page: this.data.page,
      type: 1
    }
    http.get('index/trainlist', data).then(res => {
      if(res.data.length === 0){
        this.setData({
          finish: true
        })
      }
      let arr = this.data.list.concat(res.data)
      this.setData({
        list: arr
      })
      
    }).finally(res => {
      this.setData({
        loading: false
      })
    })
  },
  video(event){
    util.skip('/service/video/video?url='+event.currentTarget.dataset.content.videofile+'&name='+event.currentTarget.dataset.content.title)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.reload()
  },

  
})